Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple Runner and Locust code by introducing Locust.start and Locust.stop methods #1306

Merged
merged 6 commits into from
Apr 3, 2020

Conversation

heyman
Copy link
Member

@heyman heyman commented Apr 2, 2020

Decouples the runner code from the Locust user code by introducing Locust.start and Locust.stop methods.

The start() and stop() methods takes a gevent.pool.Group instance, and is responsible for spawning and killing a greenlet for the locust user. With this change the runner does no longer need to keep track of the state of the individual Locust instances, and the Locust instance does no longer need to be given a reference to the runner.

(This PR is based on the tasks-directly-under-locust-class branch, and shouldn't be merged until that PR is merged).

…t.stop methods.

The start() and stop() methods takes a gevent.pool.Group instance, and is responsible for spawning and killing a greenlet running the Locust instance's run() method. With this change the runner does no longer need to keep track of the state of the individual Locust instances.
…CUST_STATE_STOPPING if TaskSet.interrupt() were called with reschedule argument set to False.
@codecov
Copy link

codecov bot commented Apr 2, 2020

Codecov Report

Merging #1306 into master will increase coverage by 0.38%.
The diff coverage is 94.54%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1306      +/-   ##
==========================================
+ Coverage   79.82%   80.21%   +0.38%     
==========================================
  Files          23       23              
  Lines        2112     2118       +6     
  Branches      327      321       -6     
==========================================
+ Hits         1686     1699      +13     
+ Misses        341      339       -2     
+ Partials       85       80       -5     
Impacted Files Coverage Δ
locust/runners.py 75.84% <88.23%> (+0.01%) ⬆️
locust/core.py 95.62% <97.36%> (+1.77%) ⬆️
locust/web.py 90.00% <0.00%> (+0.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 014d9a5...07d1ee6. Read the comment docs.

…ntial race condition from preventing locust user to die
@heyman heyman requested a review from cyberw April 2, 2020 15:22
locust/core.py Outdated
task_set_instance = self._task_set(self)
try:
if hasattr(self, "on_start"):
Copy link
Collaborator

@cyberw cyberw Apr 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be possible to define an on_start/on_stop method on the TaskSet base class that does nothing? Instead of checking whether they exist...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that might be better. I guess that any performance difference should be negligible (haven't measure so I don't even know which one is fastest).

locust/core.py Outdated
"""
def run_locust(user):
"""
Main function gor Locust user greenlet. It's important that this function takes the locust
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gor? :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, will fix :)

else:
locust._state = LOCUST_STATE_STOPPING
dying.add(g)
for user in users:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you're using "user/s" instead of "locust/s" because we're renaming it? it is confusing when the comments talk about locusts but the code about users :P

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I figured we're renaming it, and even before we've done that I don't think user can be mistaken for anything else in that context.

@cyberw
Copy link
Collaborator

cyberw commented Apr 2, 2020

Big thumbs up, apart from the minor questions/issues I mentioned.

…be implemented by end-user test scripts.

Fix bug where the TaskSet.on_stop method weren't called for nested TaskSets (only called for the first TaskSet immediately under the Locust). Should fix #1206.
@heyman
Copy link
Member Author

heyman commented Apr 2, 2020

@cyberw:
Thanks! All you mentioned issues have now been addressed I think. This PR now also fixes #1206.

@cyberw
Copy link
Collaborator

cyberw commented Apr 2, 2020

I'm ok to merge!

@heyman heyman changed the base branch from tasks-directly-under-locust-class to master April 3, 2020 15:28
@heyman heyman marked this pull request as ready for review April 3, 2020 15:29
@heyman heyman merged commit 2a0a6ef into master Apr 3, 2020
@heyman heyman deleted the locust-start-stop-refactor branch April 14, 2020 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants